Skip to content

Use eachById in mailbox:clean #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 25, 2025
Merged

Use eachById in mailbox:clean #137

merged 6 commits into from
Jul 25, 2025

Conversation

cwilby
Copy link
Contributor

@cwilby cwilby commented Jun 14, 2025

I added mailbox:clean to an application that has been using this package for several years, and noticed that older emails weren't being cleared out unless I ran the command multiple times.

Reading the command, I noticed it used chunk when deleting records. The problem with chunk in this context is that it uses offset/limit pagination under the hood. As rows are deleted in each chunk, the remaining rows shift, causing the next chunk to skip some records. This results in incomplete deletions unless the command is repeatedly executed.

To verify the issue, I modified CleanEmailsTest to create 200 records instead of 60, which caused the test to fail due to records being skipped.

To fix this, the command now uses eachById, which paginates based on primary key rather than offset. This avoids skipping rows during deletion, since it always continues from the last seen ID, not a shifting offset.

mechelon and others added 5 commits March 7, 2025 09:34
"Implicitly marking parameter $container as nullable is deprecated, the explicit nullable type must be used instead"
Fix for a deprecated parameter:
@mechelon mechelon self-requested a review July 18, 2025 15:03
@mechelon mechelon changed the base branch from master to dev July 25, 2025 09:51
@mechelon
Copy link
Member

Perfect, thank you!

@mechelon mechelon merged commit c38e197 into beyondcode:dev Jul 25, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants